'''
Created on 2010/07/06

@author: yukiyonezawa
'''
from pyrfid.Util.Util import Util
import sys

from pyrfid.DataProtocol.DSFID.DataFormat.DataFormatUtil import DataFormatUtil
from pyrfid.asn1.Encoder import Encoder
from pyrfid.DataProtocol.DSFID.Processor.Decompactor import Decompactor
from pyrfid.DataProtocol.AddObject import AddObject

class FullFeatured(object):
    
    DATA_FORMAT_ID = 1
    
    def __init__(self):
        pass
    
    
    def formattingDataSet(self, existing_data_set_list, data_set_list):
        
        data_set_list = DataFormatUtil.encodeLengthOfIdentifier(data_set_list)
        for data_set in data_set_list:
            existing_data_set_list.append(data_set)        
        return existing_data_set_list 
    
    def decodeDataSetToAddData(self, data_set_list):
        
        add_objects_list = []
        for data_set in data_set_list:
            encoded_object_identifier = ""
            if data_set.OBJECT_IDENTIFIER != "":
                encoded_object_identifier = data_set.OBJECT_IDENTIFIER
            else:
                encoded_object_identifier = int(data_set.PRECURSOR[4:], 2)
            
            object_compaction_type = data_set.getCompactionType()
            object_value = Decompactor.decompactObject(object_compaction_type, data_set.OBJECT)
            add_objects_list.append(AddObject(encoded_object_identifier, False, object_value, AddObject.COMPACT, False))
        
        return add_objects_list    
    
    